package GUIDemo;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import www.xfOnline.BAO.JDBCDAO;
import www.xfOnline.message.User;

public class tableTest extends JFrame{

	public static void main(String[] args) {
		tableTest t = new tableTest();
	}	
	public  tableTest(){
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JFrame f = new JFrame();
		JPanel jp = new JPanel();
		JTable table = new JTable();
		JScrollPane spanel = new JScrollPane();
		JDBCDAO jbao = new JDBCDAO();
		User u = new User();
		User user = new User();
		Object[] column={"学号","姓名"};
		//String sql="select name from user where account=?";
		String sql2="select q.QAName,t.tegName from qa q,tag t, relative r where q.QAID=r.QAID AND t.tagID=r.tagID";
		String title[] = {"yi ","er ","san "};
		String date[][]={{"1","2","3"},{"1","2","3"}};
		int i = 0;
		f.setBounds(200, 300, 500, 400);
		//u = jbao.findOne(sql, new Object[]{10001}, user.getClass());
		ArrayList<Object[]> result=null;
		result = jbao.findAll(sql2,new Object[]{},2);
		System.out.println(result.size());
		Object[][] obj =null;
		obj = ArrayListToArray(result);
		DefaultTableModel dtable = new DefaultTableModel(obj,column);
		table.setModel(dtable);
		spanel.setViewportView(table);
		jp.add(spanel);
		f.add(jp);
		f.setVisible(true);
		
		//System.out.println(obj[0].length);
		f.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
	}
	public Object[][] ArrayListToArray(ArrayList<Object[]> arrayList){
		int row = arrayList.size();
		int com = arrayList.get(0).length;
		int i=0,j=0;
		Object[][] obj = new Object[row][com];
			for(i=0;i<row;i++){
				for(j=0;j<com;j++){
				obj[i][j]=arrayList.get(i)[j];
				}
			}
		return obj;
	}
}
